﻿Public Class CtlOdemeEmri
	Inherits ComboBox

	Sub New()
		MyBase.new()
		Value = ""
		Size = MinimumSize
		List = False
	End Sub

	Dim _Info As String
	Private Property Info As String
		Get
			Return _Info
		End Get
		Set(value As String)
			_Info = value
			Invalidate()
		End Set
	End Property
	Public Overrides Sub OnCreateDropDown()
		Results.AddColumns("(No;c;45),(Tarih;d;65),(Açıklama;l;100%),(Tutar;m;65)")
	End Sub

	Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
		MyBase.OnPaint(e)
		Dim R = ClientRectangle
		R.Offset(50, 0)
		R.Width -= 50
		DrawText2(e.Graphics, Info, New Font(Font.Name, Font.Size - 2), ForeColor, R, StrFormat("lm"))
	End Sub

	Public Overrides Function GetDropDownControl() As System.Windows.Forms.Control
		Dim Rs As Recordset = Muhasebe.OdemeEmri.SonGirilenler(Process.Remote)
		Results.Font = New Font(Font.Name, Font.Size - 2)
		Results.Rows.Clear()
		For Each Row In Rs
			Results.Rows.Add(Rs("eno"), Rs("tarih"), Rs("alacakli"), Rs("cektoplam"))
		Next
		Results.MinimumSize = New Size(Width + 4, Math.Min(10, Results.Rows.Count) * Results.Rows(0).Height + Results.ColumnHeadersHeight)
		Results.MaximumSize = Results.MinimumSize
		Return Results
	End Function

	Public Overrides Property Value As Object
		Get
			Return Text
		End Get
		Set(Value As Object)
			Text = Value
		End Set
	End Property

	Public Overrides ReadOnly Property IsEmpty As Boolean
		Get
			Return Value = ""
		End Get
	End Property

	Public Overrides Sub OnItemClicked()
		ShowResult(Results.SelectedRows(0).Cells(0).Value)
	End Sub

	Protected Overrides Sub OnLeave(e As System.EventArgs)
		MyBase.OnLeave(e)
		If Not IsDirty Then Return
		ShowResult(Text)
	End Sub

	Sub ShowResult(eno As Integer)
		Dim Rs As Recordset = Muhasebe.OdemeEmri.Oku(Process.Remote, eno)
		If Rs.EOF Then MsgBox("Ödeme emri bulunamadı.") : Return
		Text = eno
		Info = DMY(Rs("tarih")) & " - " & Rs("alacakli")
	End Sub

	Overrides Property MinimumSize() As System.Drawing.Size
		Get
			Return New Size(360, ControlHeight)
		End Get
		Set(ByVal Value As System.Drawing.Size)
			MyBase.MinimumSize = Value
		End Set
	End Property

	Overrides Property MaximumSize() As System.Drawing.Size
		Get
			Return MinimumSize
		End Get
		Set(ByVal Value As System.Drawing.Size)
			MyBase.MaximumSize = Value
		End Set
	End Property

	Protected Overrides Sub OnSizeChanged(e As System.EventArgs)
		MyBase.OnSizeChanged(e)
		If Size.Height <> ControlHeight Then Size = New Size(Width, ControlHeight)
	End Sub

	Protected Overrides Sub OnTextChanged(e As System.EventArgs)
		MyBase.OnTextChanged(e)
		Info = ""
	End Sub

	Public Overrides Sub Reset()
		MyBase.Reset()
		Info = "Ödeme emri bilgisi"
	End Sub

End Class
